package dao.impl;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import dao.OyxUser_level_infDao;
import entity.User_Inf;
import entity.User_level_inf;
import util.C3P0Util;

public class OyxUser_level_infDaoImpl implements OyxUser_level_infDao {

	//设计方法用于返回操作数据库的qr对象
		private QueryRunner getQueryRunner(){
			return new QueryRunner(C3P0Util.getDataSource());
		}
	//通过User_Inf表 用户user_level查询User_level_inf表里的积分等级对应信息
	@Override
	public User_level_inf getUser_levelMessage(Integer user_level) {
		QueryRunner qr = this.getQueryRunner();
		User_level_inf user_level_inf=null;
		String sql = "SELECT * FROM user_level_inf WHERE user_level=?";
		try {
			user_level_inf = qr.query(sql,user_level,new BeanHandler<User_level_inf>(User_level_inf.class));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return user_level_inf;
	}
	//查询会员等级人数总个数
	@Override
	public Integer getRows(Integer lever) {
		QueryRunner qr = this.getQueryRunner();
		//编写sql 语句 
		String sql = "SELECT COUNT(userId)  FROM `user_inf` WHERE user_level=?;";
		//查询结果  
		Long i = null;
		try {
			i=(Long)qr.query(sql,lever, new ScalarHandler(1));
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return i.intValue();
	}

}
